﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommandBinding.Model;
using System.Windows.Input;

namespace CommandBinding.ViewModel
{
    public class CommandViewModel : ViewModelBase
    {
        /// <summary>
        /// If you have any data which you need to get from data base or da layer use this.
        /// </summary>
        private IModel model;
        private ICommand helloButtonCommand;
        private string textBlockTest;

        /// <summary>
        /// Initializes a new instance of the <see cref="CommandViewModel"/> class.
        /// </summary>
        /// <param name="model">The model.</param>
        public CommandViewModel(IModel model)
        {
            this.model = model;
        }

        /// <summary>
        /// Gets the hello button command.
        /// Button click event is routed from here and is binded with Hello button click/Command event 
        /// </summary>
        /// <value>The hello button command.</value>
        public ICommand HelloButtonCommand
        {
            get
            {
                if (this.helloButtonCommand == null)
                {
                    this.helloButtonCommand = new RelayCommand(param => this.HelloButton(), param => true);
                }

                return this.helloButtonCommand;
            }
        }

        /// <summary>
        /// Gets or sets the text block test.
        /// This is binded with Text block
        /// </summary>
        /// <value>The text block test.</value>
        public string TextBlockTest
        {
            get
            {
                return this.textBlockTest;
            }

            set
            {
                this.textBlockTest = value;
                OnPropertyChanged("TextBlockTest");
            }
        }

        /// <summary>
        /// This is like button click event code.
        /// </summary>
        private void HelloButton()
        {
            this.TextBlockTest = this.model.TextBlockText;
        }
    }
}
